package com.d5xx.hunters.events;

import com.d5xx.hunters.API.Hunter;
import com.d5xx.hunters.API.HunterPlayer;
import org.bukkit.Bukkit;

import java.util.concurrent.atomic.AtomicLong;

import static com.d5xx.hunters.Variables.*;

public class MapEmpty {
    public static void onMapEmpty() {
        AtomicLong time = new AtomicLong(System.currentTimeMillis());
        Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
            if (worldList.size() > 1) return;
            if (Hunter.getOnlinePlayer().isEmpty() &
                    System.currentTimeMillis() - time.get() > config.getInt("settings.plugin-reload-colddown") * 1200L) {
                time.set(System.currentTimeMillis());

                Bukkit.getScheduler().runTask(plugin, Bukkit::reload);

            }else if (Hunter.getGamingPlayer().isEmpty()) {
                Bukkit.getScheduler().runTask(plugin, () -> {

                    for (HunterPlayer hunterPlayer : Hunter.getOnlinePlayer()) {
                        hunterPlayer.getPlayer().kickPlayer(hunterPlayer.getKeyMessage("player-kick-createMap"));
                    }
                    Bukkit.reload();

                });
            }
        }, 0L, 1200L);
    }

}
